﻿using System;

namespace EOSCRM.Web.Common
{
    public class Diagnostics
    {
        public int StartTime { get; set; }
        public int EndTime { get; set; }
        private string _actionName;

        public Diagnostics(string actionName)
        {
            _actionName = actionName;
        }

        public void Begin()
        {
            StartTime = Environment.TickCount;
        }

        public void End()
        {
            EndTime = Environment.TickCount;
            OutputExecutionTime();
        }

        public void OutputExecutionTime()
        {
            var executionTime = (EndTime - StartTime) / 1000.0;
            System.Diagnostics.Trace.Write(string.Format("\nExecution time for \"{0}\"is {1} seconds.\n", _actionName, executionTime));
        }
    }
}
